package ar.com.bdf.ipharma.communications.serial;

import java.io.IOException;
import java.io.OutputStream;

import javax.comm.NoSuchPortException;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;

public class BasicWritePort {

	private SerialPort puertoSerie;
	private OutputStream salida = null;

	public BasicWritePort(String namePort) throws NoSuchPortException,
			PortInUseException, UnsupportedCommOperationException, IOException {
		
		puertoSerie = HandlerPort.getInstance(namePort);
		salida = puertoSerie.getOutputStream();
	}
	
	public void write(String cadena) throws IOException{
		salida.write(cadena.getBytes());
		salida.flush();
	}
	
	public void closeSalida() throws IOException{
		if (salida != null){
			salida.close();
			salida = null;
		}
	}
	public void close() throws IOException{
		closeSalida();
	}
}
